import React from 'react';
import CommonList from '../../../../components/CommonLists/list';
import { Button, message } from 'antd';
import services from '../../../../services/api';
import Compare from './compare';
import Modal from '../../../../components/Modal';

class VersionList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'version';
    this.detailButton = (record) => {
      return (
        <Button size='small' type='link' onClick={() => this.handleCompare(record)}>
          对比
        </Button>
      );
    };
    this.resetButton = (record) => {
      return (
        <Button size='small' type='link' onClick={() => this.handleReset(record)}>
          还原
        </Button>
      );
    };
    this.btnGroup = [this.detailButton, this.resetButton];
  }

  // 删除时的参数
  getDeleteParam = (record) => {
    return { id: record.case_category_id };
  };

  handleCompare = (record) => {
    Modal.open({
      title: '对比',
      width: '1000px',
      content: <Compare record={record} closeModal={() => Modal.close()} {...this.props} />,
      maskClosable: false,
      isOkBtn: false,
      isCancelBtn: true,
      cancel: () => {
        Modal.close();
      },
    });
  };

  handleReset = async ({ third_list_param_version_id }) => {
    const { code, msg } = await services[this.api].reset({ third_list_param_version_id });
    if (!code) {
      message.success(msg);
    } else {
      message.error(msg);
    }
  };
}

export default VersionList;
